home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / elispman.lha / elispman / elisp-17 (.txt) < prev    next >
GNU Info File  |  1993-06-01  |  46KB  |  832 lines

  1. This is Info file elisp, produced by Makeinfo-1.55 from the input file
  2. elisp.texi.
  3.    This is edition 2.0 of the GNU Emacs Lisp Reference Manual, for
  4. Emacs Version 19.
  5.    Published by the Free Software Foundation, 675 Massachusetts Avenue,
  6. Cambridge, MA 02139 USA
  7.    Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  8.    Permission is granted to make and distribute verbatim copies of this
  9. manual provided the copyright notice and this permission notice are
  10. preserved on all copies.
  11.    Permission is granted to copy and distribute modified versions of
  12. this manual under the conditions for verbatim copying, provided that
  13. the entire resulting derived work is distributed under the terms of a
  14. permission notice identical to this one.
  15.    Permission is granted to copy and distribute translations of this
  16. manual into another language, under the above conditions for modified
  17. versions, except that this permission notice may be stated in a
  18. translation approved by the Foundation.
  19. File: elisp,  Node: Accessing Documentation,  Next: Keys in Documentation,  Prev: Documentation Basics,  Up: Documentation
  20. Access to Documentation Strings
  21. ===============================
  22.  - Function: documentation-property SYMBOL PROPERTY &optional VERBATIM
  23.      This function returns the documentation string that is recorded
  24.      SYMBOL's property list under property PROPERTY.  This uses the
  25.      function `get', but does more than that: it also retrieves the
  26.      string from the file `emacs/etc/DOC-VERSION' if necessary, and
  27.      runs `substitute-command-keys' to substitute the actual (current)
  28.      key bindings.
  29.      If VERBATIM is non-`nil', that inhibits running
  30.      `substitute-command-keys'.  (The VERBATIM argument exists only as
  31.      of Emacs 19.)
  32.           (documentation-property 'command-line-processed
  33.              'variable-documentation)
  34.                => "t once command line has been processed"
  35.           (symbol-plist 'command-line-processed)
  36.                => (variable-documentation 188902)
  37.  - Function: documentation FUNCTION &optional VERBATIM
  38.      This function returns the documentation string of FUNCTION.  If
  39.      the documentation string is stored in the `emacs/etc/DOC-VERSION'
  40.      file, this function will access it there.
  41.      In addition, `documentation' runs `substitute-command-keys' on the
  42.      resulting string, so the value contains the actual (current) key
  43.      bindings.  (This is not done if VERBATIM is non-`nil'; the
  44.      VERBATIM argument exists only as of Emacs 19.)
  45.      The function `documentation' signals a `void-function' error
  46.      unless FUNCTION has a function definition.  However, FUNCTION does
  47.      not need to have a documentation string.  If there is no
  48.      documentation string, `documentation' returns `nil'.
  49.    Here is an example of using the two functions, `documentation' and
  50. `documentation-property', to display the documentation strings for
  51. several symbols in a `*Help*' buffer.
  52.      (defun describe-symbols (pattern)
  53.        "Describe the Emacs Lisp symbols matching PATTERN.
  54.      All symbols that have PATTERN in their name are described
  55.      in the `*Help*' buffer."
  56.        (interactive "sDescribe symbols matching: ")
  57.        (let ((describe-func
  58.               (function
  59.                (lambda (s)
  60.      ;; Print description of symbol.
  61.                  (if (fboundp s)             ; It is a function.
  62.                      (princ
  63.                       (format "%s\t%s\n%s\n\n" s
  64.                         (if (commandp s)
  65.                             (let ((keys (where-is-internal s)))
  66.                               (if keys
  67.                                   (concat
  68.                                    "Keys: "
  69.                                    (mapconcat 'key-description
  70.                                               keys " "))
  71.                                 "Keys: none"))
  72.                           "Function")
  73.      (or (documentation s)
  74.                             "not documented"))))
  75.      
  76.                  (if (boundp s)              ; It is a variable.
  77.      (princ
  78.                       (format "%s\t%s\n%s\n\n" s
  79.                         (if (user-variable-p s)
  80.                             "Option " "Variable")
  81.      (or (documentation-property
  82.                               s 'variable-documentation)
  83.                             "not documented")))))))
  84.              sym-list)
  85.      ;; Build a list of symbols that match pattern.
  86.          (mapatoms (function
  87.                     (lambda (sym)
  88.                       (if (string-match pattern (symbol-name sym))
  89.                           (setq sym-list (cons sym sym-list))))))
  90.      ;; Display the data.
  91.          (with-output-to-temp-buffer "*Help*"
  92.            (mapcar describe-func (sort sym-list 'string<))
  93.            (print-help-return-message))))
  94.    The `describe-symbols' function works like `apropos', but provides
  95. more information.
  96.      (describe-symbols "goal")
  97.      
  98.      ---------- Buffer: *Help* ----------
  99.      goal-column     Option
  100.      *Semipermanent goal column for vertical motion, as set by C-x C-n, or nil.
  101.      set-goal-column Command: C-x C-n
  102.      Set the current horizontal position as a goal for C-n and C-p.
  103.      Those commands will move to this position in the line moved to
  104.      rather than trying to keep the same horizontal position.
  105.      With a non-nil argument, clears out the goal column
  106.      so that C-n and C-p resume vertical motion.
  107.      The goal column is stored in the variable `goal-column'.
  108.      temporary-goal-column   Variable
  109.      Current goal column for vertical motion.
  110.      It is the column where point was
  111.      at the start of current run of vertical motion commands.
  112.      When the `track-eol' feature is doing its job, the value is 9999.
  113.      ---------- Buffer: *Help* ----------
  114.  - Function: Snarf-documentation FILENAME
  115.      This function is used only during Emacs initialization, just before
  116.      the runnable Emacs is dumped.  It finds the file offsets of the
  117.      documentation strings stored in the file FILENAME, and records
  118.      them in the in-core function definitions and variable property
  119.      lists in place of the actual strings.  *Note Building Emacs::.
  120.      Emacs finds the file FILENAME in the `emacs/etc' directory.  When
  121.      the dumped Emacs is later executed, the same file is found in the
  122.      directory `data-directory'.  Usually FILENAME is `"DOC-VERSION"'.
  123.  - Variable: data-directory
  124.      This variable holds the name of the directory in which Emacs finds
  125.      certain data files that come with Emacs or are built as part of
  126.      building Emacs.  (In older Emacs versions, this directory was the
  127.      same as `exec-directory'.)
  128. File: elisp,  Node: Keys in Documentation,  Next: Describing Characters,  Prev: Accessing Documentation,  Up: Documentation
  129. Substituting Key Bindings in Documentation
  130. ==========================================
  131.    This function makes it possible for you to write a documentation
  132. string that enables a user to display information about the current,
  133. actual key bindings.  if you call `documentation' with non-`nil'
  134. VERBATIM, you might later call this function to do the substitution
  135. that you prevented `documentation' from doing.
  136.  - Function: substitute-command-keys STRING
  137.      This function returns STRING with certain special substrings
  138.      replaced by the actual (current) key bindings.  This permits the
  139.      documentation to be displayed with accurate information about key
  140.      bindings.  (The key bindings may be changed by the user between
  141.      the time Emacs is built and the time that the documentation is
  142.      asked for.)
  143.      This table lists the forms of the special substrings and what they
  144.      are replaced with:
  145.     `\[COMMAND]'
  146.           is replaced either by a keystroke sequence that will invoke
  147.           COMMAND, or by `M-x COMMAND' if COMMAND is not bound to any
  148.           key sequence.
  149.     `\{MAPVAR}'
  150.           is replaced by a summary of the value of MAPVAR, taken as a
  151.           keymap.  (The summary is made by `describe-bindings'.)
  152.     `\<MAPVAR>'
  153.           makes this call to `substitute-command-keys' use the value of
  154.           MAPVAR as the keymap for future `\[COMMAND]' substrings.
  155.           This special string does not produce any replacement text
  156.           itself; it only affects the replacements done later.
  157.      *Please note:* each `\' must be doubled when written in a string
  158.      in Emacs Lisp.
  159.      Here are examples of the special substrings:
  160.           (substitute-command-keys
  161.              "To abort recursive edit, type: \\[abort-recursive-edit]")
  162.           
  163.           => "To abort recursive edit, type: C-]"
  164.           (substitute-command-keys
  165.              "The keys that are defined for the minibuffer here are:
  166.             \\{minibuffer-local-must-match-map}")
  167.           
  168.           => "The keys that are defined for the minibuffer here are:
  169.           
  170.           ?               minibuffer-completion-help
  171.           SPC             minibuffer-complete-word
  172.           TAB             minibuffer-complete
  173.           LFD             minibuffer-complete-and-exit
  174.           RET             minibuffer-complete-and-exit
  175.           C-g             abort-recursive-edit
  176.           "
  177.           (substitute-command-keys
  178.              "To abort a recursive edit from the minibuffer, type\
  179.           \\<minibuffer-local-must-match-map>\\[abort-recursive-edit].")
  180.           => "To abort a recursive edit from the minibuffer, type C-g."
  181. File: elisp,  Node: Describing Characters,  Next: Help Functions,  Prev: Keys in Documentation,  Up: Documentation
  182. Describing Characters for Help Messages
  183. =======================================
  184.    These functions convert events, key sequences or characters to
  185. textual descriptions.  These descriptions are useful for including
  186. arbitrary text characters or key sequences in messages, because they
  187. convert non-printing characters to sequences of printing characters.
  188. The description of a printing character is the character itself.
  189.  - Function: key-description SEQUENCE
  190.      This function returns a string containing the Emacs standard
  191.      notation for the input events in SEQUENCE.  The argument SEQUENCE
  192.      may be a string, vector or list.  *Note Input Events::, for more
  193.      information about valid events.  See also the examples for
  194.      `single-key-description', below.
  195.  - Function: single-key-description EVENT
  196.      This function returns a string describing EVENT in the standard
  197.      Emacs notation for keyboard input.  A normal printing character is
  198.      represented by itself, but a control character turns into a string
  199.      starting with `C-', a meta character turns into a string starting
  200.      with `M-', and space, linefeed, etc. are transformed to `SPC',
  201.      `LFD', etc.  A function key is represented by its name.  An event
  202.      which is a list is represented by the name of the symbol in the CAR
  203.      of the list.
  204.           (single-key-description ?\C-x)
  205.                => "C-x"
  206.           (key-description "\C-x \M-y \n \t \r \f123")
  207.                => "C-x SPC M-y SPC LFD SPC TAB SPC RET SPC C-l 1 2 3"
  208.           (single-key-description 'C-mouse-1)
  209.                => "C-mouse-1"
  210.  - Function: text-char-description CHARACTER
  211.      This function returns a string describing CHARACTER in the
  212.      standard Emacs notation for characters that appear in text--like
  213.      `single-key-description', except that control characters are
  214.      represented with a leading caret (which is how control characters
  215.      in Emacs buffers are usually displayed).
  216.           (text-char-description ?\C-c)
  217.                => "^C"
  218.           (text-char-description ?\M-m)
  219.                => "M-m"
  220.           (text-char-description ?\C-\M-m)
  221.                => "M-^M"
  222. File: elisp,  Node: Help Functions,  Prev: Describing Characters,  Up: Documentation
  223. Help Functions
  224. ==============
  225.    Emacs provides a variety of on-line help functions, all accessible to
  226. the user as subcommands of the prefix `C-h'.  For more information
  227. about them, see *Note Help: (emacs)Help.  Here we describe some
  228. program-level interfaces to the same information.
  229.  - Command: apropos REGEXP &optional DO-ALL PREDICATE
  230.      This function finds all symbols whose names contain a match for the
  231.      regular expression REGEXP, and returns a list of them.  It also
  232.      displays the symbols in a buffer named `*Help*', each with a
  233.      one-line description.
  234.      If DO-ALL is non-`nil', then `apropos' also shows key bindings for
  235.      the functions that are found.
  236.      If PREDICATE is non-`nil', it should be a function to be called on
  237.      each symbol that has matched REGEXP.  Only symbols for which
  238.      PREDICATE returns a non-`nil' value are listed or displayed.
  239.      In the first of the following examples, `apropos' finds all the
  240.      symbols with names containing `exec'.  In the second example, it
  241.      finds and returns only those symbols that are also commands.  (We
  242.      don't show the output that results in the `*Help*' buffer.)
  243.           (apropos "exec")
  244.                => (Buffer-menu-execute command-execute exec-directory
  245.               exec-path execute-extended-command execute-kbd-macro
  246.               executing-kbd-macro executing-macro)
  247.           (apropos "exec" nil 'commandp)
  248.                => (Buffer-menu-execute execute-extended-command)
  249.      The command `C-h a' (`command-apropos') calls `apropos', but
  250.      specifies a PREDICATE to restrict the output to symbols that are
  251.      commands.  The call to `apropos' looks like this:
  252.           (apropos string t 'commandp)
  253.  - Command: super-apropos REGEXP &optional DO-ALL
  254.      This function differs from `apropos' in that it searches
  255.      documentation strings as well as symbol names for matches for
  256.      REGEXP.  By default, it searches only the documentation strings,
  257.      and only those of functions and variables that are included in
  258.      Emacs when it is dumped.  If DO-ALL is non-`nil', it scans the
  259.      names and documentation strings of all functions and variables.
  260.  - Command: help-command
  261.      This command is not a function, but rather a symbol which is
  262.      equivalent to the keymap called `help-map'.  It is defined in
  263.      `help.el' as follows:
  264.           (define-key global-map "\C-h" 'help-command)
  265.           (fset 'help-command help-map)
  266.  - Variable: help-map
  267.      The value of this variable is a local keymap for characters
  268.      following the Help key, `C-h'.
  269.  - Function: print-help-return-message &optional FUNCTION
  270.      This function builds a string which is a message explaining how to
  271.      restore the previous state of the windows after a help command.
  272.      After building the message, it applies FUNCTION to it if FUNCTION
  273.      is non-`nil'.  Otherwise it calls `message' to display it in the
  274.      echo area.
  275.      This function expects to be called inside a
  276.      `with-output-to-temp-buffer' special form, and expects
  277.      `standard-output' to have the value bound by that special form.
  278.      For an example of its use, see the example in the section
  279.      describing the `documentation' function (*note Accessing
  280.      Documentation::.).
  281.      The constructed message will have one of the forms shown below.
  282.           ---------- Echo Area ----------
  283.           Type C-x 1 to remove help window.
  284.           ---------- Echo Area ----------
  285.           ---------- Echo Area ----------
  286.           Type C-x 4 b RET to restore old contents of help window.
  287.           ---------- Echo Area ----------
  288.  - Variable: help-char
  289.      The value of this variable is the character that Emacs recognizes
  290.      as meaning Help.  When Emacs reads this character (which is
  291.      usually 8, the value of `C-h'), Emacs evaluates `(eval
  292.      help-form)', and displays the result if it is a string.  If
  293.      `help-form''s value is `nil', this character is read normally.
  294.  - Variable: help-form
  295.      The value of this variable is a form to execute when the character
  296.      `help-char' is read.  If the form returns a string, that string is
  297.      displayed.  If `help-form' is `nil', then the help character is
  298.      not recognized.
  299.      Entry to the minibuffer binds this variable to the value of
  300.      `minibuffer-help-form'.
  301.    The following two functions are found in the library `helper'.  They
  302. are for modes that want to provide help without relinquishing control,
  303. such as the "electric" modes.  You must load that library with
  304. `(require 'helper)' in order to use them.  Their names begin with
  305. `Helper' to distinguish them from the ordinary help functions.
  306.  - Command: Helper-describe-bindings
  307.      This command pops up a window displaying a help buffer containing a
  308.      listing of all of the key bindings from both the local and global
  309.      keymaps.  It works by calling `describe-bindings'.
  310.  - Command: Helper-help
  311.      This command provides help for the current mode.  It prompts the
  312.      user in the minibuffer with the message `Help (Type ? for further
  313.      options)', and then provides assistance in finding out what the key
  314.      bindings are, and what the mode is intended for.  It returns `nil'.
  315.      This can be customized by changing the map `Helper-help-map'.
  316. File: elisp,  Node: Files,  Next: Backups and Auto-Saving,  Prev: Documentation,  Up: Top
  317. Files
  318. *****
  319.    In Emacs, you can find, create, view, save, and otherwise work with
  320. files and file directories.  This chapter describes most of the
  321. file-related functions of Emacs Lisp, but a few others are described in
  322. *Note Buffers::, and those related to backups and auto-saving are
  323. described in *Note Backups and Auto-Saving::.
  324. * Menu:
  325. * Visiting Files::           Reading files into Emacs buffers for editing.
  326. * Saving Buffers::           Writing changed buffers back into files.
  327. * Reading from Files::       Reading files into buffers without visiting.
  328. * Writing to Files::         Writing new files from parts of buffers.
  329. * File Locks::               Locking and unlocking files, to prevent
  330.                                simultaneous editing by two people.
  331. * Information about Files::  Testing existence, accessibility, size of files.
  332. * Contents of Directories::  Getting a list of the files in a directory.
  333. * Create/Delete Dirs::         Creating and Deleting Directories.
  334. * Changing File Attributes:: Renaming files, changing protection, etc.
  335. * File Names::               Decomposing and expanding file names.
  336. * Magic File Names::         Defining "magic" special handling
  337.                    for certain file names.
  338. File: elisp,  Node: Visiting Files,  Next: Saving Buffers,  Up: Files
  339. Visiting Files
  340. ==============
  341.    Visiting a file means reading a file into a buffer.  Once this is
  342. done, we say that the buffer is "visiting" that file, and call the file
  343. "the visited file" of the buffer.
  344.    A file and a buffer are two different things.  A file is information
  345. recorded permanently in the computer (unless you delete it).  A buffer,
  346. on the other hand, is information inside of Emacs that will vanish at
  347. the end of the editing session (or when you kill the buffer).  Usually,
  348. a buffer contains information that you have copied from a file; then we
  349. say the buffer is visiting that file.  The copy in the buffer is what
  350. you modify with editing commands.  Such changes to the buffer do not
  351. change the file; therefore, to make the changes permanent, you must
  352. "save" the buffer, which means copying the altered buffer contents back
  353. into the file.
  354.    In spite of the distinction between files and buffers, people often
  355. refer to a file when they mean a buffer and vice-versa.  Indeed, we say,
  356. "I am editing a file," rather than, "I am editing a buffer which I will
  357. soon save as a file of the same name."  Humans do not usually need to
  358. make the distinction explicit.  When dealing with a computer program,
  359. however, it is good to keep the distinction in mind.
  360. * Menu:
  361. * Visiting Functions::         The usual interface functions for visiting.
  362. * Subroutines of Visiting::    Lower-level subroutines that they use.
  363. File: elisp,  Node: Visiting Functions,  Next: Subroutines of Visiting,  Up: Visiting Files
  364. Functions for Visiting Files
  365. ----------------------------
  366.    This section describes the functions normally used to visit files.
  367. For historical reasons, these functions have names starting with
  368. `find-' rather than `visit-'.  *Note Buffer File Name::, for functions
  369. and variables that access the visited file name of a buffer or that
  370. find an existing buffer by its visited file name.
  371.  - Command: find-file FILENAME
  372.      This function reads the file FILENAME into a buffer and displays
  373.      that buffer in the selected window so that the user can edit it.
  374.      The body of the `find-file' function is very simple and looks like
  375.      this:
  376.           (switch-to-buffer (find-file-noselect filename))
  377.      (See `switch-to-buffer' in *Note Displaying Buffers::.)
  378.      When `find-file' is called interactively, it prompts for FILENAME
  379.      in the minibuffer.
  380.  - Function: find-file-noselect FILENAME
  381.      This function is the guts of all the file-visiting functions.  It
  382.      reads a file into a buffer and returns the buffer.  You may then
  383.      make the buffer current or display it in a window if you wish, but
  384.      this function does not do so.
  385.      If no buffer is currently visiting FILENAME, then one is created
  386.      and the file is visited.  If FILENAME does not exist, the buffer
  387.      is left empty, and `find-file-noselect' displays the message `New
  388.      file' in the echo area.
  389.      If a buffer is already visiting FILENAME, then the
  390.      `find-file-noselect' function uses that buffer rather than creating
  391.      a new one.  However, it does verify that the file has not changed
  392.      since it was last visited or saved in that buffer.  If the file
  393.      has changed, then this function asks the user whether to reread
  394.      the changed file.  If the user says `yes', any changes previously
  395.      made in the buffer are lost.
  396.      The `find-file-noselect' function calls `after-find-file' after
  397.      the file is read in (*note Subroutines of Visiting::.).  The
  398.      `after-find-file' function sets the buffer major mode, parses local
  399.      variables, warns the user if there exists an auto-save file more
  400.      recent than the file just visited, and finishes by running the
  401.      functions in `find-file-hooks'.
  402.      The `find-file-noselect' function returns the buffer that is
  403.      visiting the file FILENAME.
  404.           (find-file-noselect "/etc/fstab")
  405.                => #<buffer fstab>
  406.  - Command: find-alternate-file FILENAME
  407.      This function reads the file FILENAME into a buffer and selects
  408.      it, killing the buffer current at the time the command is run.  It
  409.      is useful if you have visited the wrong file by mistake, so that
  410.      you can get rid of the buffer that you did not want to create, at
  411.      the same time as you visit the file you intended.
  412.      When this function is called interactively, it prompts for
  413.      FILENAME.
  414.  - Command: find-file-other-window FILENAME
  415.      This function visits the file FILENAME and displays its buffer in
  416.      a window other than the selected window.  It may use another
  417.      existing window or split a window; see *Note Displaying Buffers::.
  418.      When this function is called interactively, it prompts for
  419.      FILENAME.
  420.  - Command: find-file-read-only FILENAME
  421.      This function visits the file named FILENAME and selects its
  422.      buffer, just like `find-file', but it marks the buffer as
  423.      read-only.  *Note Read Only Buffers::, for related functions and
  424.      variables.
  425.      When this function is called interactively, it prompts for
  426.      FILENAME.
  427.  - Command: view-file FILENAME
  428.      This function views FILENAME in View mode, returning to the
  429.      previous buffer when done.  View mode is a mode that allows you to
  430.      skim rapidly through the file but does not let you modify it.
  431.      After loading the file, `view-file' runs the normal hook
  432.      `view-hook' using `run-hooks'.  *Note Hooks::.
  433.      When this function is called interactively, it prompts for
  434.      FILENAME.
  435.  - Variable: find-file-hooks
  436.      The value of this variable is a list of functions to be called
  437.      after a file is visited.  The file's local-variables specification
  438.      (if any) will have been processed before the hooks are run.  The
  439.      buffer visiting the file is current when the hook functions are
  440.      run.
  441.      This variable could be a normal hook, but we think that renaming it
  442.      would not be advisable.
  443.  - Variable: find-file-not-found-hooks
  444.      The value of this variable is a list of functions to be called when
  445.      `find-file' or `find-file-noselect' is passed a nonexistent
  446.      FILENAME.  These functions are called as soon as the error is
  447.      detected.  `buffer-file-name' is already set up.  The functions are
  448.      called in the order given, until one of them returns non-`nil'.
  449.      This is not a normal hook because the values of the functions are
  450.      used and they may not all be run.
  451. File: elisp,  Node: Subroutines of Visiting,  Prev: Visiting Functions,  Up: Visiting Files
  452. Subroutines of Visiting
  453. -----------------------
  454.    The `find-file-noselect' function uses the `create-file-buffer' and
  455. `after-find-file' functions as subroutines.  Sometimes it is useful to
  456. call them directly.
  457.  - Function: create-file-buffer FILENAME
  458.      This function creates a suitably named buffer for visiting
  459.      FILENAME, and returns it.  The string FILENAME (sans directory) is
  460.      used unchanged if that name is free; otherwise, a string such as
  461.      `<2>' is appended to get an unused name.  See also *Note Creating
  462.      Buffers::.
  463.      *Please note:* `create-file-buffer' does *not* associate the new
  464.      buffer with a file and does not make it the current buffer.
  465.           (create-file-buffer "foo")
  466.                => #<buffer foo>
  467.           (create-file-buffer "foo")
  468.                => #<buffer foo<2>>
  469.           (create-file-buffer "foo")
  470.                => #<buffer foo<3>>
  471.      This function is used by `find-file-noselect'.  It uses
  472.      `generate-new-buffer' (*note Creating Buffers::.).
  473.  - Function: after-find-file &optional ERROR WARN
  474.      This function is called by `find-file-noselect' and by the default
  475.      revert function (*note Reverting::.).  It sets the buffer major
  476.      mode, and parses local variables (*note Auto Major Mode::.).
  477.      If there was an error in opening the file, the calling function
  478.      should pass ERROR a non-`nil' value.  In that case,
  479.      `after-find-file' issues a warning: `(New File)'.  Note that, for
  480.      serious errors, you would not even call `after-find-file'.  Only
  481.      "file not found" errors get here with a non-`nil' ERROR.
  482.      If WARN is non-`nil', then this function issues a warning if an
  483.      auto-save file exists and is more recent than the visited file.
  484.      The last thing `after-find-file' does is call all the functions in
  485.      `find-file-hooks'.
  486. File: elisp,  Node: Saving Buffers,  Next: Reading from Files,  Prev: Visiting Files,  Up: Files
  487. Saving Buffers
  488. ==============
  489.    When you edit a file in Emacs, you are actually working on a buffer
  490. that is visiting that file--that is, the contents of the file are
  491. copied into the buffer and the copy is what you edit.  Changes to the
  492. buffer do not change the file until you "save" the buffer, which means
  493. copying the contents of the buffer into the file.
  494.  - Command: save-buffer &optional BACKUP-OPTION
  495.      This function saves the contents of the current buffer in its
  496.      visited file if the buffer has been modified since it was last
  497.      visited or saved.  Otherwise it does nothing.
  498.      `save-buffer' is responsible for making backup files.  Normally,
  499.      BACKUP-OPTION is `nil', and `save-buffer' makes a backup file only
  500.      if this is the first save or if the buffer was previously
  501.      modified.  Other values for BACKUP-OPTION request the making of
  502.      backup files in other circumstances:
  503.         * With an argument of 4 or 64, reflecting 1 or 3 `C-u''s, the
  504.           `save-buffer' function marks this version of the file to be
  505.           backed up when the buffer is next saved.
  506.         * With an argument of 16 or 64, reflecting 2 or 3 `C-u''s, the
  507.           `save-buffer' function unconditionally backs up the previous
  508.           version of the file before saving it.
  509.  - Command: save-some-buffers &optional SAVE-SILENTLY-P EXITING
  510.      This command saves some modified file-visiting buffers.  Normally
  511.      it asks the user about each buffer.  But if SAVE-SILENTLY-P is
  512.      non-`nil', it saves all the file-visiting buffers without querying
  513.      the user.
  514.      The optional EXITING argument, if non-`nil', requests this
  515.      function to offer also to save certain other buffers that are not
  516.      visiting files.  These are buffers that have a non-`nil' local
  517.      value of `buffer-offer-save'.  (A user who says yes to saving one
  518.      of these is asked to specify a file name to use.)  The
  519.      `save-buffers-kill-emacs' function passes a non-`nil' value for
  520.      this argument.
  521.  - Variable: buffer-offer-save
  522.      When this variable is non-`nil' in a buffer, Emacs offers to save
  523.      the buffer on exit even if the buffer is not visiting a file.  The
  524.      variable is automatically local in all buffers.  Normally, Mail
  525.      mode (used for editing outgoing mail) sets this to `t'.
  526.  - Command: write-file FILENAME
  527.      This function writes the current buffer into file FILENAME, makes
  528.      the buffer visit that file, and marks it not modified.  The buffer
  529.      is renamed to correspond to FILENAME unless that name is already
  530.      in use.
  531.  - Variable: write-file-hooks
  532.      The value of this variable is a list of functions to be called
  533.      before writing out a buffer to its visited file.  If one of them
  534.      returns non-`nil', the file is considered already written and the
  535.      rest of the functions are not called, nor is the usual code for
  536.      writing the file executed.
  537.      If a function in `write-file-hooks' returns non-`nil', it is
  538.      responsible for making a backup file (if that is appropriate).  To
  539.      do so, execute the following code:
  540.           (or buffer-backed-up (backup-buffer))
  541.      You might wish to save the file modes value returned by
  542.      `backup-buffer' and use that to set the mode bits of the file that
  543.      you write.  This is what `basic-save-buffer' does when it writes a
  544.      file in the usual way.
  545.      Here is an example showing how to add an element to
  546.      `write-file-hooks' but avoid adding it twice:
  547.           (or (memq 'my-write-file-hook write-file-hooks)
  548.               (setq write-file-hooks
  549.                     (cons
  550.                     'my-write-file-hook write-file-hooks)))
  551.  - Variable: local-write-file-hooks
  552.      This works just like `write-file-hooks', but it is intended to be
  553.      made local to particular buffers.  It's not a good idea to make
  554.      `write-file-hooks' local to a buffer--use this variable instead.
  555.      The variable is marked as a permanent local, so that changing the
  556.      major mode does not alter a buffer-local value.  This is
  557.      convenient for packages that read "file" contents in special ways,
  558.      and set up hooks to save the data in a corresponding way.
  559.  - Variable: write-contents-hooks
  560.      This works just like `write-file-hooks', but it is intended to be
  561.      used for hooks that pertain to the contents of the file, as
  562.      opposed to hooks that pertain to where the file came from.
  563.  - Variable: after-save-hook
  564.      This normal hook runs after a buffer has been saved in its visited
  565.      file.
  566.  - Variable: file-precious-flag
  567.      If this variable is non-`nil', then `save-buffer' protects against
  568.      I/O errors while saving by writing the new file to a temporary
  569.      name instead of the name it is supposed to have, and then renaming
  570.      it to the intended name after it is clear there are no errors.
  571.      This procedure prevents problems such as a lack of disk space from
  572.      resulting in an invalid file.
  573.      (This feature worked differently in older Emacs versions.)
  574.      Some modes set this non-`nil' locally in particular buffers.
  575.  - User Option: require-final-newline
  576.      This variable determines whether files may be written out that do
  577.      *not* end with a newline.  If the value of the variable is `t',
  578.      then Emacs silently puts a newline at the end of the file whenever
  579.      the buffer being saved does not already end in one.  If the value
  580.      of the variable is non-`nil', but not `t', then Emacs asks the
  581.      user whether to add a newline each time the case arises.
  582.      If the value of the variable is `nil', then Emacs doesn't add
  583.      newlines at all.  `nil' is the default value, but a few major modes
  584.      set it to `t' in particular buffers.
  585. File: elisp,  Node: Reading from Files,  Next: Writing to Files,  Prev: Saving Buffers,  Up: Files
  586. Reading from Files
  587. ==================
  588.    You can copy a file from the disk and insert it into a buffer using
  589. the `insert-file-contents' function.  Don't use the user-level command
  590. `insert-file' in a Lisp program, as that sets the mark.
  591.  - Function: insert-file-contents FILENAME &optional VISIT
  592.      This function inserts the contents of file FILENAME into the
  593.      current buffer after point. It returns a list of the absolute file
  594.      name and the length of the data inserted.  An error is signaled if
  595.      FILENAME is not the name of a file that can be read.
  596.      If VISIT is non-`nil', it also marks the buffer as unmodified and
  597.      sets up various fields in the buffer so that it is visiting the
  598.      file FILENAME: these include the buffer's visited file name and
  599.      its last save file modtime.  This feature is used by
  600.      `find-file-noselect' and you should probably not use it yourself.
  601.    If you want to pass a file name to another process so that another
  602. program can read the file, see the function `file-local-copy' in *Note
  603. Magic File Names::.
  604. File: elisp,  Node: Writing to Files,  Next: File Locks,  Prev: Reading from Files,  Up: Files
  605. Writing to Files
  606. ================
  607.    You can write the contents of a buffer, or part of a buffer, directly
  608. to a file on disk using the `append-to-file' and `write-region'
  609. functions.  Don't use these functions to write to files that are being
  610. visited; that could cause confusion in the mechanisms for visiting.
  611.  - Command: append-to-file START END FILENAME
  612.      This function appends the contents of the region delimited by
  613.      START and END in the current buffer to the end of file FILENAME.
  614.      If that file does not exist, it is created.  This function returns
  615.      `nil'.
  616.      An error is signaled if FILENAME specifies a nonwritable file, or
  617.      a nonexistent file in a directory where files cannot be created.
  618.  - Command: write-region START END FILENAME &optional APPEND VISIT
  619.      This function writes the region (of the current buffer) delimited
  620.      by START and END into the file specified by FILENAME.
  621.      If START is a string, then `write-region' writes or appends that
  622.      string, rather than text from the buffer.
  623.      If APPEND is non-`nil', then the region is appended to the
  624.      existing file contents (if any).
  625.      If VISIT is `t', then Emacs establishes an association between the
  626.      buffer and the file: the buffer is then visiting that file.  It
  627.      also sets the last file modification time for the current buffer to
  628.      FILENAME's modtime, and marks the buffer as not modified.  This
  629.      feature is used by `write-file' and you should probably not use it
  630.      yourself.
  631.      If VISIT is a string, it specifies the file name to visit.  This
  632.      way, you can write the data to one file (FILENAME) while recording
  633.      the buffer as visiting another file (VISIT).  The argument VISIT
  634.      is used in the echo area message and also for file locking; VISIT
  635.      is stored in `buffer-file-name'.  This feature is used to
  636.      implement `file-precious-flag'; don't use it yourself unless you
  637.      really know what you're doing.
  638.      Normally, `write-region' displays a message `Wrote file FILENAME'
  639.      in the echo area.  If VISIT is neither `t' nor `nil' nor a string,
  640.      then this message is inhibited.  This feature is useful for
  641.      programs that use files for internal purposes, files which the
  642.      user does not need to know about.
  643. File: elisp,  Node: File Locks,  Next: Information about Files,  Prev: Writing to Files,  Up: Files
  644. File Locks
  645. ==========
  646.    When two users edit the same file at the same time, they are likely
  647. to interfere with each other.  Emacs tries to prevent this situation
  648. from arising by recording a "file lock" when a file is being modified.
  649. Emacs can then detect the first attempt to modify a buffer visiting a
  650. file that is locked by another Emacs job, and ask the user what to do.
  651.    File locks do not work properly when multiple machines can share
  652. file systems, such as with NFS.  Perhaps a better file locking system
  653. will be implemented in the future.  When file locks do not work, it is
  654. possible for two users to make changes simultaneously, but Emacs can
  655. still warn the user who saves second.  Also, the detection of
  656. modification of a buffer visiting a file changed on disk catches some
  657. cases of simultaneous editing; see *Note Modification Time::.
  658.  - Function: file-locked-p FILENAME
  659.      This function returns `nil' if the file FILENAME is not locked by
  660.      this Emacs process.  It returns `t' if it is locked by this Emacs,
  661.      and it returns the name of the user who has locked it if it is
  662.      locked by someone else.
  663.           (file-locked-p "foo")
  664.                => nil
  665.  - Function: lock-buffer &optional FILENAME
  666.      This function locks the file FILENAME, if the current buffer is
  667.      modified.  The argument FILENAME defaults to the current buffer's
  668.      visited file.  Nothing is done if the current buffer is not
  669.      visiting a file, or is not modified.
  670.  - Function: unlock-buffer
  671.      This function unlocks the file being visited in the current buffer,
  672.      if the buffer is modified.  If the buffer is not modified, then
  673.      the file should not be locked, so this function does nothing.  It
  674.      also does nothing if the current buffer is not visiting a file.
  675.  - Function: ask-user-about-lock FILE OTHER-USER
  676.      This function is called when the user tries to modify FILE, but it
  677.      is locked by another user name OTHER-USER.  The value it returns
  678.      tells Emacs what to do next:
  679.         * A value of `t' tells Emacs to grab the lock on the file.  Then
  680.           this user may edit the file and OTHER-USER loses the lock.
  681.         * A value of `nil' tells Emacs to ignore the lock and let this
  682.           user edit the file anyway.
  683.         * This function may instead signal a `file-locked' error, in
  684.           which case the change to the buffer which the user was about
  685.           to make does not take place.
  686.           The error message for this error looks like this:
  687.                error--> File is locked: FILE OTHER-USER
  688.           where `file' is the name of the file and OTHER-USER is the
  689.           name of the user who has locked the file.
  690.      The default definition of this function asks the user to choose
  691.      what to do.  If you wish, you can replace the `ask-user-about-lock'
  692.      function with your own version that decides in another way.  The
  693.      code for its usual definition is in `userlock.el'.
  694. File: elisp,  Node: Information about Files,  Next: Contents of Directories,  Prev: File Locks,  Up: Files
  695. Information about Files
  696. =======================
  697.    The functions described in this section are similar in as much as
  698. they all operate on strings which are interpreted as file names.  All
  699. have names that begin with the word `file'.  These functions all return
  700. information about actual files or directories, so their arguments must
  701. all exist as actual files or directories unless otherwise noted.
  702.    Most of the file-oriented functions take a single argument,
  703. FILENAME, which must be a string.  The file name is expanded using
  704. `expand-file-name', so `~' is handled correctly, as are relative file
  705. names (including `../').  Environment variable substitutions, such as
  706. `$HOME', are not recognized by these functions.  *Note File Name
  707. Expansion::.
  708. * Menu:
  709. * Testing Accessibility::   Is a given file readable?  Writable?
  710. * Kinds of Files::          Is it a directory?  A symbolic link?
  711. * Truenames::            Eliminating symbolic links from a file name.
  712. * File Attributes::         How large is it?  Any other names?  Etc.
  713. File: elisp,  Node: Testing Accessibility,  Next: Kinds of Files,  Up: Information about Files
  714. Testing Accessibility
  715. ---------------------
  716.    These functions test for permission to access a file in specific
  717. ways.
  718.  - Function: file-exists-p FILENAME
  719.      This function returns `t' if a file named FILENAME appears to
  720.      exist.  This does not mean you can necessarily read the file, only
  721.      that you can find out its attributes.  (On Unix, this is true if
  722.      the file exists and you have execute permission on the containing
  723.      directories, regardless of the protection of the file itself.)
  724.      If the file does not exist, or if fascist access control policies
  725.      prevent you from finding the attributes of the file, this function
  726.      returns `nil'.
  727.  - Function: file-readable-p FILENAME
  728.      This function returns `t' if a file named FILENAME exists and you
  729.      can read it.  It returns `nil' otherwise.
  730.           (file-readable-p "files.texi")
  731.                => t
  732.           (file-exists-p "/usr/spool/mqueue")
  733.                => t
  734.           (file-readable-p "/usr/spool/mqueue")
  735.                => nil
  736.  - Function: file-executable-p FILENAME
  737.      This function returns `t' if a file named FILENAME exists and you
  738.      can execute it.  It returns `nil' otherwise.  If the file is a
  739.      directory, execute permission means you can access files inside
  740.      the directory.
  741.  - Function: file-writable-p FILENAME
  742.      This function returns `t' if FILENAME can be written or created by
  743.      you.  It is writable if the file exists and you can write it.  It
  744.      is creatable if the file does not exist, but the specified
  745.      directory does exist and you can write in that directory.
  746.      `file-writable-p' returns `nil' otherwise.
  747.      In the third example below, `foo' is not writable because the
  748.      parent directory does not exist, even though the user could create
  749.      it.
  750.           (file-writable-p "~rms/foo")
  751.                => t
  752.           (file-writable-p "/foo")
  753.                => nil
  754.           (file-writable-p "~rms/no-such-dir/foo")
  755.                => nil
  756.  - Function: file-accessible-directory-p DIRNAME
  757.      This function returns `t' if you have permission to open existing
  758.      files in directory DIRNAME; otherwise (and if there is no such
  759.      directory), it returns `nil'.  The value of DIRNAME may be either
  760.      a directory name or the file name of a directory.
  761.      Example: after the following,
  762.           (file-accessible-directory-p "/foo")
  763.                => nil
  764.      we can deduce that any attempt to read a file in `/foo/' will give
  765.      an error.
  766.  - Function: file-newer-than-file-p FILENAME1 FILENAME2
  767.      This functions returns `t' if the file FILENAME1 is newer than
  768.      file FILENAME2.  If FILENAME1 does not exist, it returns `nil'.
  769.      If FILENAME2 does not exist, it returns `t'.
  770.      You can use `file-attributes' to get a file's last modification
  771.      time as a list of two numbers.  *Note File Attributes::.
  772.      In the following example, assume that the file `aug-19' was
  773.      written on the 19th, and `aug-20' was written on the 20th.  The
  774.      file `no-file' doesn't exist at all.
  775.           (file-newer-than-file-p "aug-19" "aug-20")
  776.                => nil
  777.           (file-newer-than-file-p "aug-20" "aug-19")
  778.                => t
  779.           (file-newer-than-file-p "aug-19" "no-file")
  780.                => t
  781.           (file-newer-than-file-p "no-file" "aug-19")
  782.                => nil
  783. File: elisp,  Node: Kinds of Files,  Next: Truenames,  Prev: Testing Accessibility,  Up: Information about Files
  784. Distinguishing Kinds of Files
  785. -----------------------------
  786.    This section describes how to distinguish directories and symbolic
  787. links from ordinary files.
  788.  - Function: file-symlink-p FILENAME
  789.      If FILENAME is a symbolic link, the `file-symlink-p' function
  790.      returns the file name to which it is linked.  This may be the name
  791.      of a text file, a directory, or even another symbolic link, or of
  792.      no file at all.
  793.      If FILENAME is not a symbolic link (or there is no such file),
  794.      `file-symlink-p' returns `nil'.
  795.           (file-symlink-p "foo")
  796.                => nil
  797.           (file-symlink-p "sym-link")
  798.                => "foo"
  799.           (file-symlink-p "sym-link2")
  800.                => "sym-link"
  801.           (file-symlink-p "/bin")
  802.                => "/pub/bin"
  803.  - Function: file-directory-p FILENAME
  804.      This function returns `t' if FILENAME is the name of an existing
  805.      directory, `nil' otherwise.
  806.           (file-directory-p "~rms")
  807.                => t
  808.           (file-directory-p "~rms/lewis/files.texi")
  809.                => nil
  810.           (file-directory-p "~rms/lewis/no-such-file")
  811.                => nil
  812.           (file-directory-p "$HOME")
  813.                => nil
  814.           (file-directory-p
  815.            (substitute-in-file-name "$HOME"))
  816.                => t
  817. File: elisp,  Node: Truenames,  Next: File Attributes,  Prev: Kinds of Files,  Up: Information about Files
  818. Truenames
  819. ---------
  820.    The "truename" of a file is the name that you get by following
  821. symbolic links until none remain, then expanding to get rid of `.' and
  822. `..' as components.  Strictly speaking, a file need not have a unique
  823. truename; the number of distinct truenames a file has is equal to the
  824. number of hard links to the file.  However, truenames are useful
  825. because they eliminate symbolic links as a cause of name variation.
  826.  - Function: file-truename FILENAME
  827.      The function `file-truename' returns the true name of the file
  828.      FILENAME.  This is the name that you get by following symbolic
  829.      links until none remain.  The argument must be an absolute file
  830.      name.
  831.    *Note Buffer File Name::, for related information.
  832.